package com.zcc.makingfriend.controller;

import com.zcc.makingfriend.dao.TbUserConcerned;
import com.zcc.makingfriend.dao.User;
import com.zcc.makingfriend.service.TbUserConcernedService;
import com.zcc.makingfriend.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zcc
 */
@Api(tags = "关注管理")
@RestController
@RequestMapping("/concerned")
public class TbUserConcernedController {

    @Autowired
    TbUserConcernedService tbUserConcernedService;

    @ApiOperation("关注用户")
    @PostMapping("/concerned")
    public Result concerned(@RequestBody TbUserConcerned tbUserConcerned){
        int i = tbUserConcernedService.addTbUserConcerned(tbUserConcerned);
        if (i == 1) {
            return Result.success("已关注");
        }
        return Result.fail("关注失败");
    }

    @ApiOperation("取消用户")
    @DeleteMapping("/disConcerned/{userId}/{concernedId}")
    public Result disConcerned(@PathVariable Long userId, @PathVariable Long concernedId){
        int i = tbUserConcernedService.deleteTbUserConcerned(userId, concernedId);
        if (i == 1) {
            return Result.success("已取消关注");
        }
        return Result.fail("取消关注失败");
    }

    @ApiOperation("统计粉丝")
    @GetMapping("/countFans/{concernedId}")
    public Result countFans(@PathVariable Long concernedId){
        int i = tbUserConcernedService.getFanNumbers(concernedId);
        return Result.success(i);
    }

    @ApiOperation("统计关注者")
    @GetMapping("/countConcerneds/{userId}")
    public Result countConcerneds(@PathVariable Long userId){
        int i = tbUserConcernedService.getConcernedNumbers(userId);
        return Result.success(i);
    }

    @ApiOperation("获取粉丝信息")
    @GetMapping("/getFanInfo/{concernedId}")
    public Result getFanInfo(@PathVariable Long concernedId){
        List<User> fans = tbUserConcernedService.getFans(concernedId);
        return Result.success(fans);
    }

    @ApiOperation("获取关注者信息")
    @GetMapping("/getConcernedInfo/{userId}")
    public Result getConcernedInfo(@PathVariable Long userId){
        List<User> fans = tbUserConcernedService.getConcerneds(userId);
        return Result.success(fans);
    }

    @ApiOperation("判断是否关注")
    @GetMapping("/isConcerned/{userId}/{concernedId}")
    public Result isConcerned(@PathVariable Long userId, @PathVariable Long concernedId){
        boolean fans = tbUserConcernedService.isConcerned(userId, concernedId);
        return Result.success(fans);
    }
}
